import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import datetime
class BaseAction(webapp.RequestHandler):
    def go(self,values,path1,path2='../../template'):
        path = os.path.join(os.path.dirname(__file__), path2, path1)
        #print path
        if values is None:
        	self.response.out.write(template.render(path, values))
        else:
	        name=self.request.cookies.get('name')  
	        if(name is None):
	        	pass
	        else:	
	        	values['name']=name
	        self.response.out.write(template.render(path, values))
        
        
    def json(self,fileIds,list):
    	json="{totalCount:"+'4'+",items:[ "
    	for l in list:
    		json+="{"
    		for attr in fileIds:
    			s=getattr(l,attr)
    			if isinstance(s, datetime.datetime):
    				json+=attr+":'"+ str( s )+"'," 
    			else:
    				json+=attr+":'"+ str( s.encode("utf-8") )+"'," 	
    		json=json[0:-1]+"},"
    	json=json[0:-1]+"]}"	
    	return json	
    def get(self):
    	name=self.request.cookies.get('name')  
    	if name is None:
    		self.go(None,'login.htm')
    	else:
    		self._get()
    			   
        
